<html>
<%--
  *登录界面
  *author：lw
  *data: 2021/07/07
 --%>
<head>
    <title>login</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.bootcss.com/popper.js/1.12.5/umd/popper.min.js"></script>
    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.bootcss.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container col-xs-2 col-xs-push-4">
    <h1>Login</h1>

    <div class="form-group">
        <label for="username1">Username</label>
        <input type="text" class="form-control" id="username1" name="username" placeholder="Username">
    </div>
    <div class="form-group">
        <label for="password1">Password</label>
        <input type="password" class="form-control" id="password1" name="password" placeholder="Password">
    </div>
    <button type="submit" class="btn btn-default" id="submit_btn" onclick="login()">Submit</button>
<div>
    <script>

        window.onload = function getcookie() {
            var arrstr = document.cookie.split("; ");
            for (var i = 0; i < arrstr.length; i++) {
                var temp = arrstr[i].split("=");
                if (temp[0] == "nms_username")
                    document.getElementById('username1').value = temp[1];
                for (var i = 0; i < arrstr.length; i++) {
                    var temp = arrstr[i].split("=");
                    if (temp[0] == "nms_password")
                        document.getElementById('password1').value = temp[1];
                }

            }

        };

        function login() {
            $.ajax({
                url: "http://localhost:17793/admin/login",
                dataType: "json",
                data: {'username':$("#username1").val(),
                    'password':$("#password1").val()},
                type:"POST",
                success:function(res){

                    console.log(res);
                    if(res.code == 200){

                       window.location.href = "form.html";
                    }else
                        alert(res.obj.message);
                }
            });

        }

    </script>

</body>
</html>
